package game.block.blocks.state;

import game.block.Constants.COLOR;
import game.block.entity.MovableEntity;
import game.block.tile.Tile;

import com.badlogic.gdx.math.Vector2;

public class MoveState extends BlockState {

    private float time;
    private float timer;
    private Tile tile;
    private Vector2 originalPos;

    public MoveState(MovableEntity b, Tile tile, float time) {
        super(b);
        this.tile=tile;
        this.time = time;
        if (time == 0) {
            block.setPosition(tile.getPosition());
            exit();
        }
    }

    @Override
    public void update(float delta) {
        Vector2 temp = new Vector2(originalPos);
        temp.lerp(tile.getPosition(), timer / time);
        block.setPosition(temp);
        timer += delta;
        if (timer >= time) {
            exit();
        }
    }

    @Override
    public void enter() {
        originalPos = block.getPosition();
        timer = 0;
    }

    @Override
    public void exit() {
        block.setPosition(tile.getPosition());
        block.changeState(new NormalState(block));
        tile.changeColor(COLOR.BLANK);
    }

}
